package com.cjl.android.asynctask;

public class Test {
    public static void main(String[] args) {

        MyTask task = new MyTask(0);
        task.execute();
    }


    static class MyTask extends AsyncTask<String,Integer,String>{

        int flag;

        public MyTask(int flag) {
            this.flag = flag;
        }

        @Override
        protected String doInBackground(String... strings) {
            log("doInBackground");
            for (int i = 0; i < 100; i++) {
                publishProgress(i);
                if (i == 50){
                    flag = 1;
                }
                if (flag == 1){
                    cancel(true);
                    return "stop do inBackground";
                }
            }
            return "name";
        }

        @Override
        protected void onPreExecute() {
            log("onPreExecute");
        }

        @Override
        protected void onPostExecute(String s) {
            log("onPostExecute s:"+s);
        }

        @Override
        protected void onCancelled(String s) {
            log("onCancelled "+s);
        }

        @Override
        protected void onProgressUpdate(Integer... integers) {
            log("onProgressUpdate "+integers[0]);
        }
    }

}
